<!DOCTYPE html>
<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="shortcut icon" href="../../docs-assets/ico/favicon.png">

    <title>Signin Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <!-- <link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> -->
    <link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">

    <!-- Custom styles for this template -->
    <link href="signin.css" rel="stylesheet">
	<!-- // <script src="//cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script> -->
	<script type="text/javascript" src="/js/jquery.min.js"></script>

  </head>

  <body>
    <div class="container">
      <form id="signin_form" class="form-signin" role="form">
        <h2 class="form-signin-heading">欢迎登录</h2>
        <input id="email" type="text" class="form-control" placeholder="邮箱" required autofocus>
        <input id="password" type="password" class="form-control" placeholder="密码" required>
        <label class="checkbox">
          <input type="checkbox" value="remember-me"> 下次自动登录
        </label>
        <button id="signin_btn" class="btn btn-lg btn-primary btn-block" type="submit">立即登录</button>
      </form>

    </div> <!-- /container -->
	<script src="../js/ckbase.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
				$("#signin_form").submit(function(event){
					event.preventDefault();
					var email = $("#email").val();
					var password = $("#password").val();
					var post_data = {
						email: email,
						password: password
					};

					var request = $.ajax({
						url: "/z/login/",
						type: "POST",
						data: post_data,
						dataType: "json"
					});
					request.done(function(data) {
						switch (data.ret) {
							case 0: {
								setCookie('uid', data.uid, 1);
								setCookie('username', data.username, 1);
								location.href = '/user/';
								break;
							}
							case 1000: {
								alert("该邮箱未注册");
								$("#email").val("");
								break;
							}
							case 1001: {
								alert("密码错误");
								$("#password").val("");
								break;
							}
						}
					});
				});
		});
	</script>
  </body>
</html>
